package org.opens.config;

import lombok.extern.slf4j.Slf4j;
import org.opens.entity.City;
import org.opens.entity.City2;
import org.opens.entity.Person;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
@EnableConfigurationProperties(value = {MyProperties.class})
public class ConditionalConfig {

    private final MyProperties myProperties;

    public ConditionalConfig(MyProperties myProperties) {
        this.myProperties = myProperties;
    }

    @Bean
    public City city() {
        log.info(">>> " + myProperties);
        City city = new City();
        city.setAge(12);
        city.setName("s12");
        return city;
    }

    @Bean
    public City2 city2() {
        City2 city = new City2();
        city.setAge(12);
        city.setName("s12");
        return city;
    }

    @Bean
    @ConditionalOnBean(value = {City.class, City2.class})
    public Person person() {
        Person person = new Person();
        person.setName("qqq");
        return person;
    }

}
